package com.dzsw.stream8;

import com.google.common.base.Joiner;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StreamMain {

    static List<TestBean> list = Arrays.asList(
            new TestBean("Ron","M",10,"ron.zheng@tfschange.com",false),
            new TestBean("KDS","W",10,"kds@qq.com",false),
            new TestBean("BoDuo","W",30,"boduo@163.com",false),
            new TestBean("CangJin","W",10,"cangjin@gmail.com",false),
            new TestBean("XiaoZe","W",30,"xiaoze@hotmail.com",true),
            new TestBean("James","M",10,"leblonjames@hotmail.com",true),
            new TestBean("Allen","M",50,"allen.lei@tfschange.com",true),
            new TestBean("Smith","M",10,"jr.smith@cel.com",true),
            new TestBean("Wade","M",20,"dw.wade@cel.com",true),
            new TestBean("Wade","M",20,"dw.wade@cel.com",false)
    );

    public static void main(String[] args) {
        linq3();
    }

    public static void linq1() {
        // 获取Leader isMng = true
        List<TestBean> l = list.stream().filter(TestBean::isMng).collect(Collectors.toList());
        l.forEach(item -> {
            System.out.println(item.getName());
        });
    }

    public static void linq2() {
        List<Integer> numbers = Arrays.asList(1, 2, 1, 3, 3, 2, 4);
        numbers.stream().filter(i -> i % 2 == 0).distinct().forEach(System.out::println);
    }

    public static void linq3() {
        Joiner joiner = Joiner.on(",");
        List l = list.stream().map(TestBean::getName).collect(Collectors.toList());
        System.out.println(joiner.join(l));
    }
}
